home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.comco.com!not-for-mail
- From: sharma@comco.com (Sharma)
- Newsgroups: comp.lang.c++
- Subject: Template instantiation and inlining
- Date: 22 Feb 1996 16:50:30 -0600
- Organization: Computational Mechanics, Inc.
- Distribution: usa
- Message-ID: <4girvm$6eg@sphinx.comco.com>
- NNTP-Posting-Host: sphinx.comco.com
-
- In order to prevent multiple instantiations of templated classes (for
- similar parameter types), I want to use explicit instantiations. I
- want to place these explicit instantiations in a separate file and let
- the actual source files using templated classes 'see' the definition
- of the templated classes. What is not clear to me is if the member
- functions declared inlined (and defined in header file) will actually
- get inlined in the source file using them, if implicit template
- instantiation is turned off (can be done in gcc) ?
-
- Consider this example:
-
- file foo.h
- ----------
-
- template <class T>
- class foo {
- inline do_something() {...};
- other_functions (defined in foo.C);
- }
-
- file foo-inst.C
- ---------------
- #include "foo.h"
- #include "foo.C"
-
- template class foo<int>;
- template class foo<double>;
-
- Compilation of foo-inst.C will instantiate various foo classes
- (exactly once).
-
- file main.C
- -----------
- #include "foo.h"
-
- void main ()
- {
- foo<int> a;
- foo<double> b;
-
- a.do_something();
- b.do_something();
- }
-
- Question is: will do_something() be inlined in main, if implicit
- instantiation of foo is suppressed here (during compilation) ?
-
- A more general question would be whether inlining of member methods is
- possible without instantiation of the class itself ?
-
-
- Suresh
-